package com.acegear.horizon.controllers.vo;

import java.util.HashMap;

/**
 * Created by wangsike on 2016/12/15.
 */
public class ResultVO<T> {
	
	/**
     * 操作成功
     */
    public final static ResultVO OPTION_SUCCESS = success("option success", 0);

    public final static ResultVO FORBIDDEN = error("forbidden", 4000);
    public final static ResultVO NEED_JWT = error("need jwt", 1100);
    public final static ResultVO WRONG_JWT = error("wrong jwt", 1101);
    public final static ResultVO WRONG_ACCESS_TOKEN = error("wrong access token", 1102);
    public final static ResultVO COMMENT_NOT_FOUND = error("comment not found", 1080);
    public final static ResultVO EVENT_NOT_FOUND = error("event not found", 1070);
    public final static ResultVO EVENT_LIKE_FAILED = error("event like failed", 1071);
    public final static ResultVO EVENT_UNLIKE_FAILED = error("event unlike failed", 1072);
    /**
     * 短信发送失败
     */
    public final static ResultVO SMS_SEND_FAILED = error("sms send failed", 1060);
    /**
     * 错误的 DailyId
     */
    public final static ResultVO DAILY_NOT_FOUND = error("daily not found", 1050);
    /**
     * 帖子发送失败
     */
    public final static ResultVO POST_SEND_FAILED = error("post send failed", 1040);
    /**
     * 帖子关注失败
     */
    public final static ResultVO POST_LIKE_FAILED = error("post like failed", 1041);
    /**
     * 帖子取消关注失败
     */
    public final static ResultVO POST_UNLIKE_FAILED = error("post like failed", 1042);
    /**
     * 错误的 postId
     */
    public final static ResultVO POST_NOT_FOUND = error("post not found", 1043);

    /**
     * 删除帖子失败
     */
    public final static ResultVO POST_DELETE_FAILED = error("post delete failed", 1044);

    /**
     * 删除帖子评论失败
     */
    public final static ResultVO POSTCOMMENT_DELETE_FAILED = error("postComment delete failed", 1045);
    /**
     * 错误的 userId
     */
    public final static ResultVO USER_NOT_FOUND = error("user not found", 1030);
    /**
     * 关注用户失败
     */
    public final static ResultVO FOLLOW_ERROR = error("user already followed", 1031);
    public final static ResultVO UNFOLLOW_ERROR = error("user not followed", 1032);
    /**
     * 错误的 clubId
     */
    public final static ResultVO CLUB_NOT_FOUND = error("club not found", 1020);
    /**
     * 加入俱乐部失败
     */
    public final static ResultVO JOIN_ERROR = error("join club error", 1021);
    /**
     * 离开俱乐部失败
     */
    public final static ResultVO LEAVE_ERROR = error("leave club error", 1022);
    /**
     * 错误的用户名或者密码
     */
    public final static ResultVO INVALIDATE_PASSWORD = error("invalidate username or password", 1010);
    /**
     * 无效的登录身份
     */
    public final static ResultVO INVALIDATE_AUTH = error("invalidate user auth", 1011);
    /**
     * 安全验证 token 错误
     */
    public final static ResultVO SECURE_TOKEN_ERROR = error("secure token error", 1001);
    /**
     * 微博登录失败
     */
    public final static ResultVO WEIBO_AUTH_FAILED = error("weibo auth failed", 1002);
    /**
     * 微信登录失败
     */
    public final static ResultVO WECHAT_AUTH_FAILED = error("wechat auth failed", 1003);
    /**
     * 错误的密码
     */
    public final static ResultVO PASSWORD_ERROR = error("password error", 1014);
    /**
     * 验证码错误
     */
    public final static ResultVO VERIFY_CODE_ERROR = error("wrong verify code", 1012);
    /**
     * 邮箱已存在
     */
    public final static ResultVO EMAIL_EXIST = error("email exist", 1015);
    /**
     * 微信号已使用过
     */
    public final static ResultVO WECHAT_EXIST = error("wechat exist", 1017);
    /**
     * 微博号已使用过
     */
    public final static ResultVO WEIBO_EXIST = error("weibo exist", 1018);
    /**
     * 电话已存在
     */
    public final static ResultVO PHONE_EXIST = error("phone exist", 1016);

    /**
     * topic不存在或被删除
     */
    public final static ResultVO TOPIC_NOT_FOUND = error("topic not found", 1050);
    /**
     * 置顶失败
     */
    public final static ResultVO TOP_FAIL = error("top fail", 1051);
    /**
     * 取消置顶失败
     */
    public final static ResultVO UNTOP_FAIL = error("untop fail", 1052);
    public final static ResultVO EMPTY = new ResultVO(new HashMap<>());
    private String message;
    private Integer code;
    private T body;

    public ResultVO() {
    }

    public ResultVO(String message, Integer code, T body) {
        this.message = message;
        this.code = code;
        this.body = body;
    }

    public ResultVO(T body) {
        this.body = body;
        message = "";
        code = 0;
    }
    
    public static ResultVO success(String message, Integer code) {
        return new ResultVO<>(message, code, null);
    }

    public static ResultVO error(String message, Integer code) {
        return new ResultVO<>(message, code, null);
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getBody() {
        return body;
    }

    public void setBody(T body) {
        this.body = body;
    }
}
